import { Controller, Get, Post, Body } from '@nestjs/common';
import { AppService } from '../service/app.service';
import { DataService } from '../service/data.service';

@Controller()
export class AppController {
  constructor(
    private readonly dataService: DataService,
    private readonly appService: AppService,
  ) {}
  // --------------------------------/--------------------------------------------------
  // @Get()
  // getHello(): string {
  //   return this.appService.getHello();
  // }
  // ---------------------------------/getData-------------------------------------------------
  @Get('/getData')
  getData2() {
    return {
      status: 'success',
      data: {
        id: 1,
        name: '示例数据',
        description: '这是通过GET接口获取的数据',
        timestamp: new Date().toISOString(),
      },
    };
  }
  // --------------------------------/data--------------------------------------------------
  @Get('data')
  getData() {
    return {
      status: 'success',
      message: '数据获取成功',
      data: this.dataService.getDataSummary(),
    };
  }

  @Post('create')
  createData(@Body() body: any) {
    console.log(body.name);
    if (!body.name) {
      return {
        status: 'error',
        message: '姓名不能为空',
      };
    }
    return {
      status: 'success',
      message: '数据创建成功',
      data: {
        id: Date.now(),
        ...body,
        createdAt: new Date().toISOString(),
      },
    };
  }
}
